﻿using Autofac;

using BCVP.Net8.IService;
using BCVP.Net8.Repository.Base;
using BCVP.Net8.Service;

using Microsoft.AspNetCore.Mvc;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace BCVP.Net8
{
    /// <summary>
    /// Autofac得注册器，需要重写Load方法
    /// </summary>
    public class AutofacProperityModuleRegister : Autofac.Module
    {
        /// <summary>
        /// 重写autofac的load方法，在这里注册注入
        /// </summary>
        /// <param name="builder"></param>
        /// <exception cref="Exception"></exception>
        protected override void Load(ContainerBuilder builder)
        {
            var controllerBaseType = typeof(ControllerBase);
            builder.RegisterAssemblyTypes(typeof(Program).Assembly)
                .Where(t => controllerBaseType.IsAssignableFrom(t) && t != controllerBaseType)
                .PropertiesAutowired();

        }
    }
}
